function DoubleLinkList() {

    // 内部类：节点类
    function Node(data) {
        this.data = data
        this.prev = null
        this.next = null
    }
    // 属性
    this.head = null
    this.tail = null
    this.length = 0

    // 常见的操作方法
    // 1、append方法
    DoubleLinkList.prototype.append = function (data) {
        // 1.通过data创建一个新的节点
        const newNode = new Node(data)
        // 2.判断是否是第一个节点
        if (this.length == 0) {
            this.head = newNode //第一个节点
        } else {
            // 不是第一个节点
            let current = this.head
            while (current.next) {
                current = current.next
            }
            current.next = newNode
            newNode.prev = current
            this.tail = newNode
        }
        this.length += 1

    }
    // 2、将链表转成字符串的形式
    // 2.1 toString方法
    DoubleLinkList.prototype.toString = function () {
        return this.backwardString()
    }
    // 2.2 forwardString方法(从后向前)
    DoubleLinkList.prototype.forwardString = function () {
        // 1、定义变量
        let current = this.tail
        let resultString = ""
        while (current) {
            resultString += current.data + " "
            current = current.prev
        }
        return resultString

    }
    // 2.3 backwardString(从前向后)
    DoubleLinkList.prototype.backwardString = function () {
        // 1、定义变量
        let current = this.head
        let resultString = ""
        // 2、依次向后面遍历，获取每一个节点
        while (current) {
            resultString += current.data + ' '
            current = current.next
        }
        return resultString
    }

    // 3、insert方法
    DoubleLinkList.prototype.insert = function (position, data) {
        // 1、进行越界判断
        if (position < 0 || position > this.length) return false
        // 2、根据data来创建相应的节点
        const newNode = new Node(data)
        // 3、判断原来的列表是否为空
        if (this.length == 0) {
            this.head = newNode
            this.tail = newNode
        } else {
            // 先要判断是否是在第一个位置 poisition是0
            if (position == 0) {
                newNode.next = this.head
                this.head.prev = newNode
                this.head = newNode
            }
            let current = this.head
            let prev = null
            let index = 0
            while (index++ < position) {
                prev = current
                current = current.next
            }
            prev.next = node
        }
    }
}

// 测试代码
var list = new DoubleLinkList()

list.append("abc")
list.append("def")
list.append("opq")

// 测试转字符串的方法
console.log(list);
console.log(list.backwardString());
console.log("hello");
console.log(list.forwardString());